package com.example.book.repository

import androidx.room.*
import com.example.book.model.Book
import kotlinx.coroutines.flow.Flow

@Dao
interface BookDao {

    @Query("select * from book")
    fun getAll(): Flow<List<Book>>

    @Query("select * from book where isbn = :isbn LIMIT 1")
    fun get(isbn: String): Flow<Book>

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(vararg books: Book)

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(books: List<Book>)

    @Delete
    fun delete(book: Book)

    @Query("DELETE FROM book where isbn = :isbn")
    fun delete(isbn: String)

    @Query("DELETE FROM book")
    fun deleteAll()

    @Update
    fun update(book: Book)

    @Update(entity = Book::class)
    fun update(price: Price)

    class Price (var isbn: String, var price: String)
}